<!--
 * @Author: your name
 * @Date: 2021-08-03 13:36:05
 * @LastEditTime: 2021-08-12 13:26:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \getHome (2)\src\components\discounts\amend.vue
-->
<!--轮播图配置-->
<template>
  <div>
    <div class="center">
      <div class="hander">轮播图配置</div>
      <div class="entirety">
        <div class="search">
          <!--  账号状态搜索信息 -->

          <div class="demo-input-suffix">
            通知类型

            <el-select
              v-model="StateData"
              placeholder="请选择"
              @change="onChangeStripe"
            >
              <el-option
                v-for="item in business"
                :key="item.statusCode"
                :label="item.statusName"
                :value="item.statusCode"
              >
              </el-option>
            </el-select>
          </div>
          <div class="news">
            <el-button size="medium" @click="dialogFormVisible = true"
              >新增通知
            </el-button>
            <el-dialog title="新增通知" :visible.sync="dialogFormVisible">
              <el-form :model="form">
                <el-form-item label="通知名称" :label-width="formLabelWidth">
                  <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="通知区域" :label-width="formLabelWidth">
                  <el-select v-model="form.region" placeholder="请选择通知区域">
                    <el-option label="区域一" value="shanghai"></el-option>
                    <el-option label="区域二" value="beijing"></el-option>
                  </el-select>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  @click="dialogFormVisible = false"
                  >确 定</el-button
                >
              </div>
            </el-dialog>
          </div>
        </div>
      </div>
      <!--  员工列表栏位-->

      <div class="entirety">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="nickname" label="序号" width="120">
            <template slot-scope="scope">
              <div>
                {{ scope.row.nickname }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="nickname" label="发送节点" width="120">
            <template slot-scope="scope">
              <div>
                {{ scope.row.nickname }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="nickname" label="通知内容" width="180">
            <template slot-scope="scope">
              <div>
                {{ scope.row.nickname }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="nickname" label="通知类型" width="120">
            <template slot-scope="scope">
              <div>
                {{ scope.row.nickname }}
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="userName" label="通知状态" width="150">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                :active-value="1"
                :inactive-value="0"
                active-text="开启"
                inactive-text="关闭"
                active-color="#fb8053"
                inactive-color="#dcdfe6"
                @change="switchChange($event, scope.row)"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="170">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.staffStatus == '正常'"
                @click.native.prevent="isFrozen(scope.row.staffCode)"
                style="color: #fc9e76;"
                type="text"
                size="small"
              >
                修改
              </el-button>
              <el-button
                v-if="scope.row.staffStatus != '正常'"
                @click.native.prevent="isThaw(scope.row.staffCode)"
                style="color: #fc9e76;"
                type="text"
                size="small"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <div class="left"></div>
          <div class="right">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              class="page"
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
              :current-page="pageIndex"
              :page-size="pageSize"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      json_fields: {
        //导出Excel表格的表头设置
        员工姓名: "nickname",
        登录账号: "userName",
        员工状态: "staffStatus"
      },
      iSON: true,
      pageIndex: 1,
      pageSize: 20,
      total: 0,
      dialogTableVisible: false,
      dialogFormVisible: false,
      tableData: [],
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      staffName: "",
      staffPhone: "",
      searchValue: "",
      userSearch: 0,

      formLabelWidth: "120px",
      staffSearch: [
        { value: 0, label: "员工姓名" },
        { value: 1, label: "登录账号" }
      ],
      StateData: "",
      business: [
        {
          statusCode: "1",
          statusName: "服务认证"
        },
        {
          statusCode: "2",
          statusName: "物业缴费"
        },
        {
          statusCode: "3",
          statusName: "报事报修"
        },
        {
          statusCode: "4",
          statusName: "到家服务"
        },
        {
          statusCode: "5",
          statusName: "商品电商"
        }
      ],
      multipleSelection: []
    };
  },
  activated() {
    this.DetailByPage();
  },

  methods: {
    handleSelectionChange(val) {
      //console.log("handleSelectionChange,,,,,,,", val);
      this.multipleSelection = val;
    },

    // 切换搜索条件清空数据
    changeSelect() {
      (this.searchValue = ""), (this.staffName = ""), (this.staffPhone = "");
      this.DetailByPage();
    },

    // 精准模糊查找
    searchForUserInformation() {
      //console.log("userSearch,,,,dsdsd,", this.userSearch);
      if (this.userSearch === 0) {
        this.staffName = this.searchValue || "";
      } else {
        this.staffPhone = this.searchValue || "";
      }
      this.DetailByPage();
    },
    //冻结
    isFrozen(staffCode) {
      this.$confirm("是否冻结?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url:
              "/staffadmin/homeService/staffManager/updateStaffLoginAccountStatus",
            method: "POST",
            data: {
              staffCode,
              staffStatus: 0
            }
          }).then(res => {
            if (res.success === 0) {
              this.$message.error(res.errorMsg);
            } else {
              this.$message.success("冻结成功");
              this.DetailByPage();
            }
          });
        })
        .catch(() => {
          this.$message.error("冻结失败");
        });
    },
    //解冻
    isThaw(staffCode) {
      this.$confirm("是否解冻?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http({
            url:
              "/staffadmin/homeService/staffManager/updateStaffLoginAccountStatus",
            method: "POST",
            data: {
              staffCode,
              staffStatus: 1
            }
          }).then(res => {
            if (res.success === 0) {
              this.$message.error(res.errorMsg);
            } else {
              this.$message.success("解冻成功");
              this.DetailByPage();
            }
          });
        })
        .catch(() => {});
      this.DetailByPage();
    },
    //导出
    isExport(tableData) {
      //console.log(tableData);
    },

    // 更换状态数据
    onChangeStripe(val) {
      //console.log(val);

      this.StateData = val || "";
      this.DetailByPage();
    },
    //分页获取优惠券模板列表接口调用
    DetailByPage() {
      this.$http({
        url: `staffadmin/homeService/staffManager/fetchStaffLoginAccountList`,
        method: "GET",
        params: {
          staffStatus: this.StateData,
          staffName: this.staffName,
          staffPhone: this.staffPhone,
          page: this.pageIndex,
          size: this.pageSize
        }
      }).then(res => {
        this.tableData = res.list;

        this.total = parseInt(res.total);
      });
    },
    switchChange(e, data) {
      let url = "";
      let message = "";
      if (e == 1) {
        url = "/tpPringTemplate/enable/";
        message = "启用成功 !";
      } else if (e == 0) {
        url = "/tpPringTemplate/disable/";
        message = "停用成功 !";
      }
      this.$ajax.get(`${url + data.ptId}`).then(res => {
        if (res.code == 0) return this.$message({ type: "success", message });
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.news {
  margin-left: 60%;
}
.entirety {
  width: 95%;
  margin: 10px;
  border: 7px solid #fafafa;
  border-radius: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;

    margin-left: 1%;
  }
}

.overall {
  width: 100%;
  height: auto;
  display: flex;

  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 2%;
}
.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}

/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
</style>
